package com.demo.spring.aop.service.impl;

import com.demo.spring.aop.service.DemoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class DemoServiceImpl implements DemoService {

    @Autowired@Lazy
    DemoService thisProxy;

    @Override
    public boolean targetMethod(String param) {
        log.info("Here is in targetMethod ! param={}",param);
        return false;
    }

    @Override
    public boolean targetMethodException(String param){
        log.info("Here is in targetMethodException ! param={}",param);
        String s = null;
        return s.length()>0;
    }

    @Override
    public void invokeThis() {
        log.info("in invokeThis, before this.targetMethod");
        boolean returns = this.targetMethod("from invokeThis");
        log.info("in invokeThis, after this.targetMethod, returns is {}",returns);
    }

    @Override
    public void invokeProxy() {
        log.info("in invokeProxy, before thisProxy.targetMethod");
        boolean returns = thisProxy.targetMethod("from invokeProxy");
        log.info("in invokeProxy, after thisProxy.targetMethod, returns is {}",returns);
    }

    public void invokeException(){
        log.info("in invokeException, before thisProxy.targetMethodException");
        boolean returns = thisProxy.targetMethodException("from invokeException");
        log.info("in invokeException, after thisProxy.targetMethodException, returns is {}",returns);
    }
}
